package entity;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQuery;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

@Entity
@Table(name = "DISCOUNT_CATS")
@NamedQuery(name = "DiscountCategory.selectByName", query = "SELECT d FROM DiscountCategory d WHERE d.name = :name")
public class DiscountCategory {
	
	@Id
	@Column(name = "CAT_ID")
    @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="DEF_GEN")    
	@SequenceGenerator(name = "DEF_GEN", sequenceName = "DISC_ID_SEQ", initialValue = 4, allocationSize=1)
    private int id;
 
    public int getId() {
        return id;
    }
 
    public void setId(int id) {
        this.id = id;
    }

	@Column(name = "NAME", nullable = false)
	private String name;

	@Column(name = "AMOUNT", nullable = false)
	private int amount;

	public DiscountCategory() {
	}

	public DiscountCategory(String name, int amount) {
		this.name = name;
		this.amount = amount;
	}

	@Override
	public String toString() {
		return name;
	}
	
	@Override
	public int hashCode() {		
		int result = 42;
		result = 31 * result + id;
		result = 31 * result + name.hashCode();
		result = 31 * result + amount;
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (!(obj instanceof DiscountCategory))
			return false;
		DiscountCategory other = (DiscountCategory) obj;
		if (!(this.getId() == (other.getId())))
			return false;
		return true;
	}

}
